namespace Succell.Dnn.JQuery.UI
{
    /// <summary>
    /// Specifies options for the <see cref="Dialog.CustomPosition"/> property.
    /// </summary>
    public class DialogCustomPosition
    {
        #region constants

        /// <summary>
        /// The value for specifying a left aligned position for the Dialog.
        /// </summary>
        public const int AlignLeft = 0;

        /// <summary>
        /// The value for specifying a right aligned position for the Dialog.
        /// </summary>
        public const int AlignRight = int.MaxValue;

        /// <summary>
        /// The value for specifying a top aligned position for the Dialog.
        /// </summary>
        public const int AlignTop = 0;

        /// <summary>
        /// The value for specifying a bottom aligned position for the Dialog.
        /// </summary>
        public const int AlignBottom = int.MaxValue;

        /// <summary>
        /// The value for specifying a center aligned position for the Dialog.
        /// </summary>
        public const int AlignCenter = int.MinValue;

        #endregion

        #region static readonly fields

        /// <summary>
        /// Defines a top left alignment.
        /// </summary>
        public static readonly DialogCustomPosition TopLeft = new DialogCustomPosition(AlignLeft, AlignTop);

        /// <summary>
        /// Defines a top right alignment.
        /// </summary>
        public static readonly DialogCustomPosition TopRight = new DialogCustomPosition(AlignRight, AlignTop);

        /// <summary>
        /// Defines a bottom left alignment.
        /// </summary>
        public static readonly DialogCustomPosition BottomLeft = new DialogCustomPosition(AlignLeft, AlignBottom);

        /// <summary>
        /// Defines a bottom right alignment.
        /// </summary>
        public static readonly DialogCustomPosition BottomRight = new DialogCustomPosition(AlignRight, AlignBottom);

        #endregion

        #region properties

        /// <summary>
        /// Gets the left offset for the <see cref="Dialog"/> in pixels or one of
        /// <see cref="AlignLeft"/>, <see cref="AlignRight"/>, or <see cref="AlignCenter"/>.
        /// </summary>
        public int Left { get; private set; }

        /// <summary>
        /// Gets the top offset for the <see cref="Dialog"/> in pixels or one of
        /// <see cref="AlignTop"/>, <see cref="AlignBottom"/>, or <see cref="AlignCenter"/>.
        /// </summary>
        public int Top { get; private set; }

        #endregion

        #region constructors

        /// <summary>
        /// Creates a new <see cref="DialogCustomPosition"/> for use in the
        /// <see cref="Dialog.CustomPosition"/> property.
        /// </summary>
        /// <param name="left">The left offset for the <see cref="Dialog"/> in pixels or one of
        /// <see cref="AlignLeft"/>, <see cref="AlignRight"/>, or <see cref="AlignCenter"/>.</param>
        /// <param name="top">The top offset for the <see cref="Dialog"/> in pixels or one of
        /// <see cref="AlignTop"/>, <see cref="AlignBottom"/>, or <see cref="AlignCenter"/>.</param>
        public DialogCustomPosition(int left, int top)
        {
            this.Left = left;
            this.Top = top;
        }

        #endregion

        #region methods

        /// <summary>
        /// Gets the object[] needed for json serialization.
        /// </summary>
        /// <returns>The object[] needed for json serialization.</returns>
        public object[] ToSetting()
        {
            object[] result = new object[2];
            switch (this.Left)
            {
                case AlignLeft:
                    result[0] = "left";
                    break;
                case AlignRight:
                    result[0] = "right";
                    break;
                case AlignCenter:
                    result[0] = "center";
                    break;
                default:
                    result[0] = this.Left;
                    break;
            }
            switch (this.Top)
            {
                case AlignTop:
                    result[1] = "top";
                    break;
                case AlignBottom:
                    result[1] = "bottom";
                    break;
                case AlignCenter:
                    result[1] = "center";
                    break;
                default:
                    result[1] = this.Top;
                    break;
            }
            return result;
        }

        #endregion
    }
}